package com.literature.threeGroup.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.literature.threeGroup.mapper.*;
import com.literature.threeGroup.pojo.Order;
import com.literature.threeGroup.pojo.ResourceInfo;
import com.literature.threeGroup.pojo.ResourceUpdate;
import com.literature.threeGroup.service.ResourceMaintainService;
import com.literature.threeGroup.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class ResourceMaintainImpl implements ResourceMaintainService {
    @Autowired
    private ResourceInfoMapper resourceInfoMapper;
    @Autowired
    private ResourceUpdateMapper resourceUpdateMapper;
    @Autowired
    private AgencyCompanyMapper agencyCompanyMapper;
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public List findAll() {
        return resourceInfoMapper.findMaintainList();
    }

    @Override
    public ResourceInfo findById(String id) {
        return resourceInfoMapper.findById(id);
    }

    @Override
    public List findUpdateList() {
        return resourceUpdateMapper.selectByExample(null);
    }

    @Override
    public void updateadd(ResourceUpdate resourceUpdate){
        resourceUpdate.setId(UUID.randomUUID().toString());
        resourceUpdate.setOrderStatus(0);
        resourceUpdate.setDistributionStatus(0);
        resourceUpdate.setUpdReviewStatus(0);
        resourceUpdate.setReviewStatus(1);
        resourceUpdateMapper.insert(resourceUpdate);
    }

    @Override
    public List findOrderList() {
        return orderMapper.findOrderList();
    }

    @Override
    public PageResult findOrderList1(Order order, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        Page<ResourceUpdate> findOrder=orderMapper.findOrderList1(order);
        return new PageResult(findOrder.getTotal(),findOrder.getResult());
    }

    @Override
    public List findCompany() {
        return agencyCompanyMapper.selectByExample(null);
    }

    @Override
    public Order findOrderId(String id) {
        return orderMapper.findOrderId(id);
    }

    @Override
    public void updateOrder(String id) {
        orderMapper.updateOrder("修改成功","1");
    }

    @Override
    public PageResult findupdateList(ResourceUpdate resourceUpdate, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        Page<ResourceUpdate> findUpdate=resourceUpdateMapper.findupdateList(resourceUpdate);
        return new PageResult(findUpdate.getTotal(),findUpdate.getResult());
    }

    @Override
    public Page<ResourceInfo> findAll2(ResourceInfo resourceInfo, int page, int size) {
        PageHelper.startPage(page,size);
        Page<ResourceInfo> resourceinfos = (Page<ResourceInfo>) resourceInfoMapper.finaAll2(resourceInfo);
        return resourceinfos;
    }

    @Override
    public List<ResourceInfo> queryDevied() {
        return resourceInfoMapper.queryDevied();
    }

    @Override
    public ResourceInfo findResourceId(String id) {
        return resourceInfoMapper.findResourceId(id);
    }

    @Override
    public ResourceUpdate findResourceupId(String id) {
        return resourceUpdateMapper.findResourceupId(id);
    }


    @Override
    public ResourceUpdate findAuditId(String id) {
        return resourceUpdateMapper.findAuditId(id);
    }
}
